package com.jianganming.mediator.demo;

public class MediatorCompany {
    private HouseOwner houseOwner;
    private Tenant tenant;

    public void setHouseOwner(HouseOwner houseOwner) {
        this.houseOwner = houseOwner;
    }

    public void setTenant(Tenant tenant) {
        this.tenant = tenant;
    }

    public void connection(Person person, String message){
        if(person.equals(houseOwner)){
            //租客接受消息
            tenant.getMessage(message);
        }else{
            //房主接受消息
            houseOwner.getMessage(message);
        }
    }

    public static void main(String[] args) {
        MediatorCompany mediatorCompany = new MediatorCompany();
        HouseOwner houseOwner = new HouseOwner("张三",mediatorCompany);
        Tenant tenant = new Tenant("李四",mediatorCompany);
        mediatorCompany.setHouseOwner(houseOwner);
        mediatorCompany.setTenant(tenant);
        tenant.connection(tenant.name+"想租房子");//租客发消息
        houseOwner.connection(houseOwner.name+"来看一看吧");
    }
}
